<?php

$_SESSION['isCity'] = false;


/**
 * Get all available countries that are inserted into DB
 */
function getCountry(){
	
	// Datenbankverbindung aufbauen
	$db = new mysqli('localhost', 'root', '', 'cityguide');
	$db->set_charset("utf8");
	if (mysqli_connect_errno()) {
    	printf("Connect failed: %s\n", mysqli_connect_error());
    	exit();
	}
	
	$query = "SELECT distinct Country.name FROM COUNTRY";

	if ($stmt = $db->prepare($query)) {
		$stmt->execute();
    	$stmt->bind_result($country);
    	
    	echo "<option value='empty'> Bitte wählen.... </option>";	
    	while ($row = $stmt->fetch()) {
    		
    		$selCountry= $_POST['select-choice-0'];
    		if ($selCountry == $country) { 
              $selected = 'selected="selected"';
              $_SESSION['isCountry'] = true;
              echo "<option value='$country' ". $selected ." >" . $country. "</option>";
          	}  else{
          		echo "<option value='$country'>" . $country. "</option>";
          		
          	}    		
    	}	
    	// Statement schliessen
		$stmt->close();
	}
	// Datenbankverbindung schliesssen
	$db->close();	
}


?>